package com.paradogs.gs.modules.inventory;

import com.paradogs.gs.db.Material;
import com.paradogs.gs.misc.DBMultiRowManager;
import com.paradogs.gs.misc.annotations.GameManager;
import com.paradogs.gs.db.Consumable;
import com.paradogs.gs.modules.inventory.dao.ConsumableDao;
import com.paradogs.gs.modules.inventory.framework.ItemGainProxy;
import com.paradogs.gs.modules.inventory.framework.ItemType;

import java.util.Map;

/**
 * @author: yumi
 * @date: 2024/10/29  16:05
 * @Description: TODO
 */
@GameManager
public class ConsumableMgr extends DBMultiRowManager<ConsumableDao, Consumable> {
    @Override
    public void onInitialization(Map<Long, Consumable> data) {
    }

    @ItemGainProxy(ItemType.CONSUMABLE)
    public void itemProxy(int itemId, int count) {
        Map<Long, Consumable> dataMap = __raw__();
        if (dataMap.containsKey(itemId)) {
            Consumable consumable = dataMap.get(itemId);
            update(consumable.getId(), Consumable::setCount, consumable.getCount() + count);
        } else {
            // 新增
            __update__(new Consumable(itemId, count));
        }
    }
}
